package com.omt.tarjimdinek.domain.message.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;
import javax.validation.constraints.Size;

import org.apache.log4j.Logger;
import org.hibernate.validator.constraints.NotEmpty;

import com.google.common.base.Objects;
import com.omt.tarjimdinek.domain.islamicLibrary.entity.Sahabi;
import com.omt.tarjimdinek.domain.member.entity.CategorieNotification;
import com.omt.tarjimdinek.support.Identifiable;

/**
 * category of member private message's
 * @author chabane
 *
 */
@Entity
@Table(name="a01_ctgmsg")
public class CategorieMessage implements Identifiable<String>, Serializable{

    private static final long serialVersionUID = 1L;
    private static final Logger log = Logger.getLogger(CategorieNotification.class);
    
	/** ID SGBD */
	@Column(name="COCTGMSG", length=3)
	@Id
	private String code;
	
	@Column(name = "VERSION", precision = 10)
    @Version
    private Integer version;
	
	/** label */
	@Size(max = 45)
	@NotEmpty
	@Column(name="LICTGMSG", length=45, nullable=false, unique=true)
	private String libelle;
	
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Transient
	public boolean isIdSet() {
	    return code != null && !code.isEmpty();
	}

	/**
	 * @return the version
	 */
	public Integer getVersion() {
		return version;
	}

	/**
	 * @param version the version to set
	 */
	public void setVersion(Integer version) {
		this.version = version;
	}

	public String getId() {
		return code;
	}

	public void setId(String id) {
		code = id;
	}

	public String getLibelle() {
		return libelle;
	}

	public void setLibelle(String libelle) {
		this.libelle = libelle;
	}
	
	/**
     * equals implementation using a business key.
     */
    public boolean equals(Object other) {
        return this == other || (other instanceof Sahabi && hashCode() == other.hashCode());
    }

    public int hashCode() {
        int hashCode = Objects.hashCode(getLibelle());
        return hashCode;
    }
    
    /**
     * Construct a readable string representation for this instance.
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return Objects.toStringHelper(this) //
                .add("code", getCode()) //
                .add("libelle", getLibelle()) //
                .add("version", getVersion()) //
                .toString();
    }
}
